@extends('layouts.mobile_main')

@section('title', '推荐有奖分享')

@section('resources')
    @parent
    <link rel="stylesheet" href="{{ env('CSS_DOMAIN') }}/css/public.css?v={{env('CSS_VERSION')}}">
    <script src="{{ env('JS_DOMAIN') }}/js/adaptation.js?v={{env('JS_VERSION')}}"></script>
    <style>
		div{position: relative;}
		input{position: absolute;top: 13.3rem;left: 50%;width: 5.4rem;height: 0.8rem;border: 1px solid #ccc;margin-left: -2.8rem;padding: 0 0.1rem;}
		img{width: 5.6rem;height: 1.1rem;position: absolute;top: 14.5rem;left: 50%;margin-left: -2.8rem;}
    </style>
@endsection

@section('content')
<div style="background: url({{env('IMAGE_DOMAIN')}}/images/share_recommend.png?v={{env('IMAGE_VERSION')}}) 0 0 no-repeat;background-size: 10.8rem;height: 21.8rem;">
	<input type="text" name="mobile" value="" placeholder="请输入手机号">
	<input type="hidden"  name="parentid" value="{{$parentid}}" />
	<img id="btn" src="{{env('IMAGE_DOMAIN')}}/images/share_btn.png?v={{env('IMAGE_VERSION')}}" alt="">
</div>
@endsection

@section("scriptResources")
    @parent
    <script>
    var Web_url = '{{env('WEB_URL')}}'
	    window.onresize=function(){
		    pagesp();
	    }
	    $(function(){
	    	$('#btn').click(function(){
	    	    var mobile = $("input[name='mobile']").val();
	    	    var parentid = $("input[name='parentid']").val();
	    	    var myreg=/^(((13[0-9]{1})|(14[0-9]{1})|(17[0]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
	    	    // if((mobile == '') || (mobile.length !=11)) {
	    	    //     alert("请输入正确的手机号码");return;
	    	    // }
	    	    if(mobile == '') {
	    	    	alert("手机号不能为空");return;
	    	    }else if((mobile.length !=11)||(!myreg.test(mobile))) {
	    	    	alert("请输入有效的手机号码")
	    	    }else{
	    	    	$.ajax({
		    			url : '/mobile/share/recommend/submit',
		    			type : 'post',
		    			data : {mobile:mobile, parentid:parentid},
		    			dataType : 'json',
		    			success : function (data) {
	                        if(data.status == 'success') {
	                            alert(data.message);
	                            window.location.href=Web_url+"/mobile/app/download";
	                        } else {
	                            alert(data.message);
	                        }
		    			}
		    		})
	    	    }
	    	})
	    })
    </script>
@endsection